package com.doit.scala;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

public class KafkaProducerDemo {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"linux01:9092");
        props.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        props.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());

        props.setProperty(ProducerConfig.BATCH_SIZE_CONFIG,"1000000");
        props.setProperty(ProducerConfig.LINGER_MS_CONFIG,"10000000");

//        props.setProperty(ProducerConfig.INTERCEPTOR_CLASSES_CONFIG,MyInter.class.getName());
//        props.setProperty(ProducerConfig.PARTITIONER_CLASS_CONFIG,MyPartitioner.class.getName());
        KafkaProducer<String, String> producer = new KafkaProducer<String, String>(props);

        for (int i = 0; i < 100000000; i++) {
            producer.send(new ProducerRecord<String,String>("xxooyy",i+"AAA"));
            producer.flush();
        }
        producer.close();
    }
}
